package com.we823.cms.model.common;

import java.io.Serializable;

import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.annotation.JSONField;

public class FileModel implements Serializable {

	private static final long serialVersionUID = -7249626521039776205L;

	private boolean hasError;
    private String errorMsg;
    private MultipartFile file;
    /*
    最后显示的名字
     */
    private String finalName;
    /**
     * 原始名称
     */
    private String originalName;

    private String url;
    
    public FileModel(){}

    public FileModel(boolean hasError,String errorMsg){
        this.hasError = hasError;
        this.errorMsg = errorMsg;
    }
    /**
     *
     * @param hasError 是否包含错误
     * @param file 文件对象
     */
    public FileModel(boolean hasError, MultipartFile file, String url) {
        this(hasError,file, url, "no error");
    }

    /**
     *
     * @param hasError 是否包含错误
     * @param file 文件对象
     * @param errorMsg 错误信息
     */
    public FileModel(boolean hasError, MultipartFile file, String url, String errorMsg) {
        this(hasError,file,null,url,errorMsg);
    }

    /**
     *
     * @param hasError 是否存在错误
     * @param file 文件对象
     * @param finalName 最后显示的文件名
     * @param errorMsg 错误信息
     */
    public FileModel(boolean hasError, MultipartFile file, String finalName, String url,String errorMsg) {
        this.hasError = hasError;
        this.file = file;
        this.errorMsg = errorMsg;
        this.finalName = finalName;
        this.url = url;
    }

    public boolean isHasError() {
        return hasError;
    }

    public void setHasError(boolean hasError) {
        this.hasError = hasError;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    @JSONField(serialize=false)
    public MultipartFile getFile() {
        return file;
    }

    public void setFile(MultipartFile file) {
        this.file = file;
    }

    public String getFinalName() {
        if(finalName==null && file!=null){
            finalName = file.getOriginalFilename();
        }
        return finalName;
    }

    public void setFinalName(String finalName) {
        this.finalName = finalName;
    }

    public String getOriginalName() {
        if(originalName==null && file!=null){
            originalName = file.getOriginalFilename();
        }
        return originalName;
    }

    public void setOriginalName(String originalName) {
        this.originalName = originalName;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
}
